import { Controller, Get, Post, Body, Patch, Param, Delete, Request, Query } from "@nestjs/common";
import { UserService } from "./user.service";
import { CreateUserDto } from "./dto/create-user.dto";
import { UpdateUserDto } from "./dto/update-user.dto";
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";


@ApiTags("用户相关")
@ApiBearerAuth()
@Controller("user")
export class UserController {
	constructor(private readonly userService: UserService) {
	}
	
	@Post()
	@ApiOperation({ summary: "创建用户" })
	create(@Body() createUserDto: CreateUserDto) {
		return this.userService.create(createUserDto);
	}
	
	@Get()
	@ApiOperation({ summary: "获取用户列表" })
	findAll(@Query() dto) {
		return this.userService.findAll(dto);
	}
	
	@Patch(":id")
	@ApiOperation({ summary: "修改" })
	update(@Param("id") id: string, @Body() updateUserDto: UpdateUserDto) {
		return this.userService.update(+id, updateUserDto);
	}
	
	@Delete(":id")
	@ApiOperation({ summary: "删除" })
	remove(@Param("id") id: string) {
		return this.userService.remove(+id);
	}
	
	@Get("info")
	@ApiOperation({ summary: "查询用户信息" })
	info(@Request() req) {
		return this.userService.info(req.user.id);
	}
}

